
 <!DOCTYPE HTML>
<html >
<head>
  <meta charset="UTF-8">
  
    <title>ListenableFuture并发编程 | Typhoon&#39;s code space</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    
    <meta name="author" content="typhoon">
    

    
    <meta name="description" content="说起并发，大家都会想到多线程，当然多线程的合理使用能够提高cpu的利用率">
<meta name="keywords" content="ListenableFuture">
<meta property="og:type" content="article">
<meta property="og:title" content="ListenableFuture并发编程">
<meta property="og:url" content="http://scorpioaeolus.oschina.io/2018/09/21/ListenableFuture并发编程/index.html">
<meta property="og:site_name" content="Typhoon&#39;s code space">
<meta property="og:description" content="说起并发，大家都会想到多线程，当然多线程的合理使用能够提高cpu的利用率">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/09/21/ListenableFuture并发编程/l1.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/09/21/ListenableFuture并发编程/l2.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/09/21/ListenableFuture并发编程/l3.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/09/21/ListenableFuture并发编程/l4.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/09/21/ListenableFuture并发编程/l5.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/09/21/ListenableFuture并发编程/l6.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/09/21/ListenableFuture并发编程/l7.png">
<meta property="og:updated_time" content="2018-09-21T12:30:31.879Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="ListenableFuture并发编程">
<meta name="twitter:description" content="说起并发，大家都会想到多线程，当然多线程的合理使用能够提高cpu的利用率">
<meta name="twitter:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/09/21/ListenableFuture并发编程/l1.png">

    
    <link rel="alternative" href="/atom.xml" title="Typhoon&#39;s code space" type="application/atom+xml">
    
    
    <link rel="icon" href="/typhoon/img/java.png">
    
    
    <link rel="apple-touch-icon" href="/typhoon/img/jacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/typhoon/img/jacman.jpg">
    
    <link rel="stylesheet" href="/typhoon/css/style.css">
</head>

  <body>
    <header>
      
<div>
		
			<div id="imglogo">
				<a href="/typhoon/"><img src="/typhoon/img/java.png" alt="Typhoon&#39;s code space" title="Typhoon&#39;s code space"/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/typhoon/" title="Typhoon&#39;s code space">Typhoon&#39;s code space</a></h1>
				<h2 class="blog-motto"></h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="Menu">
			</a></div>
			<nav class="animated">
				<ul>
					<ul>
					 
						<li><a href="/typhoon/">主页</a></li>
					
						<li><a href="/typhoon/archives">归档</a></li>
					
						<li><a href="/typhoon/about">关于</a></li>
					
					<li>
 					
					<form class="search" action="//google.com/search" method="get" accept-charset="utf-8">
						<label>Search</label>
						<input type="search" id="search" name="q" autocomplete="off" maxlength="20" placeholder="Search" />
						<input type="hidden" name="q" value="site:scorpioaeolus.oschina.io">
					</form>
					
					</li>
				</ul>
			</nav>			
</div>
    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
  
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/typhoon/2018/09/21/ListenableFuture并发编程/" title="ListenableFuture并发编程" itemprop="url">ListenableFuture并发编程</a>
  </h1>
  <p class="article-author">By
       
		<a href="/typhoon/about" title="typhoon" target="_blank" itemprop="author">typhoon</a>
		
  <p class="article-time">
    <time datetime="2018-09-21T10:52:40.000Z" itemprop="datePublished"> Published 2018-09-21</time>
    
  </p>
</header>
	<div class="article-content">
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">Contents</strong>
		
			<ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#背景需求"><span class="toc-number">1.</span> <span class="toc-text">背景需求</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#方案分析"><span class="toc-number">2.</span> <span class="toc-text">方案分析</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#技术实现"><span class="toc-number">3.</span> <span class="toc-text">技术实现</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#优秀的ListenableFuture"><span class="toc-number">4.</span> <span class="toc-text">优秀的ListenableFuture</span></a></li></ol>
		
		</div>
		
		<pre><code>说起并发，大家都会想到多线程，当然多线程的合理使用能够提高cpu的利用率
</code></pre><a id="more"></a>
<pre><code>和提高请求的响应效率，使用不当会带来线程安全问题，导致数据一致性问题以及jvm
内存溢出。接着我们就分析一下并发编程和使用guava的ListenableFuture实现高效编程。
</code></pre><h5 id="背景需求"><a href="#背景需求" class="headerlink" title="背景需求"></a>背景需求</h5><pre><code>    就以退款列表为例，前端分页查询退款信息，每页展示20条数据，但是页面需要展示
的每一行退款信息不只是简单的退款相关字段，有物流信息、订单信息以及买家信息，也
就是说每一条退款数据都是以退款数据为基线，查询到的多维相关信息的整合内容。​
</code></pre><h5 id="方案分析"><a href="#方案分析" class="headerlink" title="方案分析"></a>方案分析</h5><pre><code>    对于上述需求，我们一般会有两种实现方式，分别是单线程同步查询组合并返回和多
线程异步查询组合并返回，实现思路如下：
</code></pre><p><strong>单线程</strong></p>
<img src="/typhoon/2018/09/21/ListenableFuture并发编程/l1.png" alt="ListenableFuture" title="ListenableFuture">
<p><strong>多线程</strong></p>
<img src="/typhoon/2018/09/21/ListenableFuture并发编程/l2.png" alt="ListenableFuture" title="ListenableFuture">
<pre><code>    我们可以这样假设，如果每一次外部服务调用rt是200ms，那么如果是单线程访问的话
需要循环同步调用20次，也就是外部依赖服务调用需要耗时2s；多线程的话我们可以并发开
20个线程异步调用外部服务，理论上只需要200ms，这就是并发编程的魅力所在。
</code></pre><h5 id="技术实现"><a href="#技术实现" class="headerlink" title="技术实现"></a>技术实现</h5><p><strong>单线程</strong></p>
<pre><code>业务代码实现：
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@Override</span></div><div class="line"><span class="function"><span class="keyword">public</span> List&lt;User&gt; <span class="title">selectAll</span><span class="params">()</span> </span>&#123;</div><div class="line">	List&lt;User&gt; list = <span class="keyword">this</span>.userDao.queryAll();</div><div class="line">	<span class="keyword">for</span>(User u : list) &#123;</div><div class="line">		<span class="comment">//模拟外部服务调用</span></div><div class="line">		<span class="keyword">this</span>.mockOutService(u);</div><div class="line">	&#125;</div><div class="line">	<span class="keyword">return</span> list;</div><div class="line">&#125;</div><div class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">mockOutService</span><span class="params">(User u)</span> </span>&#123;</div><div class="line">	<span class="keyword">try</span> &#123;</div><div class="line">	    u.getName();</div><div class="line">		Thread.sleep(<span class="number">200L</span>);</div><div class="line">	&#125; <span class="keyword">catch</span> (InterruptedException e) &#123;</div><div class="line">		e.printStackTrace();</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>测试代码：
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</div><div class="line">	AbstractApplicationContext context = <span class="keyword">new</span> ClassPathXmlApplicationContext(<span class="string">"spring-root.xml"</span>);</div><div class="line">	context.start();</div><div class="line">	UserService userService = context.getBean(UserService.class);</div><div class="line">	<span class="keyword">long</span> begin = System.currentTimeMillis();</div><div class="line">	List&lt;User&gt; list =  userService.selectAll();</div><div class="line">	System.out.println(<span class="string">"耗时："</span> + (System.currentTimeMillis() - begin));</div><div class="line">	<span class="keyword">for</span>(User u : list) &#123;</div><div class="line">		System.out.println(u);</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>运行测试代码：
</code></pre><img src="/typhoon/2018/09/21/ListenableFuture并发编程/l3.png" alt="ListenableFuture" title="ListenableFuture">
<pre><code>同步查询耗时1300ms。
</code></pre><p><strong>多线程</strong><br>        业务代码：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@Override</span></div><div class="line"><span class="function"><span class="keyword">public</span> List&lt;User&gt; <span class="title">selectAll2</span><span class="params">()</span> </span>&#123;</div><div class="line">List&lt;User&gt; list = <span class="keyword">this</span>.userDao.queryAll();</div><div class="line"></div><div class="line">List&lt;Future&lt;User&gt;&gt; futureList = <span class="keyword">new</span> ArrayList&lt;&gt;(list.size());</div><div class="line"><span class="keyword">for</span>(User u : list) &#123;<span class="comment">//多线程并发查询</span></div><div class="line">Future&lt;User&gt; future = executorService.submit(<span class="keyword">new</span> Callable&lt;User&gt;() &#123;</div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">public</span> User <span class="title">call</span><span class="params">()</span> <span class="keyword">throws</span> Exception </span>&#123;</div><div class="line">	<span class="keyword">return</span> mockOutService(u);</div><div class="line">    &#125;</div><div class="line">&#125;);</div><div class="line">futureList.add(future);</div><div class="line">&#125;</div><div class="line"><span class="keyword">for</span>(Future&lt;User&gt; future : futureList) &#123;<span class="comment">//获取多线程查询结果并组装</span></div><div class="line">    <span class="keyword">try</span> &#123;</div><div class="line">	User u = future.get();</div><div class="line">	u.getName();</div><div class="line">    &#125; <span class="keyword">catch</span> (InterruptedException e) &#123;</div><div class="line">	e.printStackTrace();</div><div class="line">    &#125; <span class="keyword">catch</span> (ExecutionException e) &#123;</div><div class="line">	e.printStackTrace();</div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line"><span class="keyword">return</span> list;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<pre><code>测试代码：
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</div><div class="line">	AbstractApplicationContext context = <span class="keyword">new</span> ClassPathXmlApplicationContext(<span class="string">"spring-root.xml"</span>);</div><div class="line">	context.start();</div><div class="line">	UserService userService = context.getBean(UserService.class);</div><div class="line">	<span class="keyword">long</span> begin = System.currentTimeMillis();</div><div class="line">	List&lt;User&gt; list =  userService.selectAll2();</div><div class="line">	System.out.println(<span class="string">"耗时："</span> + (System.currentTimeMillis() - begin));</div><div class="line">	<span class="keyword">for</span>(User u : list) &#123;</div><div class="line">		System.out.println(u);</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>运行测试代码：
</code></pre><img src="/typhoon/2018/09/21/ListenableFuture并发编程/l4.png" alt="ListenableFuture" title="ListenableFuture">
<pre><code>    可以看到查询效率有非常明显的提升，但是没有按照我们预期的提升四倍，是因为第一次运行过程中
中间涉及了线程池创建线程等其他问题，此处不做纠结。
</code></pre><h5 id="优秀的ListenableFuture"><a href="#优秀的ListenableFuture" class="headerlink" title="优秀的ListenableFuture"></a>优秀的ListenableFuture</h5><pre><code>    在上述代码中我们分析了单线程和多线程对查询的性能对比，可以明显发现多线程的优势所在。不知道
有没有人注意到，虽然使用jdk自带的线程池实现了多线程操作，但是获取多线程处理结果的代码是同步的：
</code></pre><img src="/typhoon/2018/09/21/ListenableFuture并发编程/l5.png" alt="ListenableFuture" title="ListenableFuture">
<pre><code>    如果调用future.get()的时候，线程还没有处理完，是需要同步等待的，也就是说需要主线程不停的轮训
多线程的处理结果，这样的话代码比较复杂并且效率也不高。
    ListenableFuture是guava中提供的对多线程的比较优秀的支持，ListenableFuture顾名思义就是可以监听
的Future，它是对java原生Future的扩展增强。我们知道Future表示一个异步计算任务，当任务完成时可以得到
计算结果。使用ListenableFuture Guava帮我们检测Future是否完成了，如果完成就自动调用回调函数，这样可
以减少并发程序的复杂度。ListenableFuture是一个接口，它从jdk的Future接口继承。
    接下来我们基于ListenableFuture来实现上述案例的并发查询：
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@Override</span></div><div class="line"><span class="function"><span class="keyword">public</span> List&lt;User&gt; <span class="title">selectAll3</span><span class="params">()</span> </span>&#123;</div><div class="line">	ExecutorService executorService = Executors.newFixedThreadPool(<span class="number">20</span>);</div><div class="line">	List&lt;User&gt; list = <span class="keyword">this</span>.userDao.queryAll();</div><div class="line">	<span class="keyword">for</span> (User u : list) &#123;<span class="comment">//多线程并发查询</span></div><div class="line">		ListenableFuture&lt;User&gt; future = listeningExecutorService.submit(<span class="keyword">new</span> Callable&lt;User&gt;() &#123;</div><div class="line">			<span class="meta">@Override</span></div><div class="line">			<span class="function"><span class="keyword">public</span> User <span class="title">call</span><span class="params">()</span> <span class="keyword">throws</span> Exception </span>&#123;</div><div class="line">				<span class="keyword">return</span> mockOutService(u);</div><div class="line">			&#125;</div><div class="line">		&#125;);</div><div class="line">		Futures.addCallback(future, <span class="keyword">new</span> FutureCallback&lt;User&gt;() &#123;</div><div class="line">			<span class="meta">@Override</span></div><div class="line">			<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onSuccess</span><span class="params">(User user)</span> </span>&#123;<span class="comment">//调用成功后要做的事情,比如把订单信息填进去</span></div><div class="line">				user.getName();</div><div class="line">			&#125;</div><div class="line">			<span class="meta">@Override</span></div><div class="line">			<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onFailure</span><span class="params">(Throwable t)</span> </span>&#123;</div><div class="line">				System.out.println(<span class="string">"occur error:"</span> + t.toString());</div><div class="line">			&#125;</div><div class="line">		&#125;);</div><div class="line">	&#125;</div><div class="line">	<span class="keyword">return</span> list;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>运行测试代码：
</code></pre><img src="/typhoon/2018/09/21/ListenableFuture并发编程/l6.png" alt="ListenableFuture" title="ListenableFuture">
<pre><code>    同样我们可以拿到结果，并且还有一定的性能提升。我们用一张图来对比jdk线程池并发编程与guava
ListenableFuture并发编程：
</code></pre><img src="/typhoon/2018/09/21/ListenableFuture并发编程/l7.png" alt="ListenableFuture" title="ListenableFuture">
<pre><code>    在日常开发中希望更多的使用guava的ListenableFuture替代jdk自带线程池的Future，能够带来更好的
性能提升。
</code></pre>  
	</div>
		<footer class="article-footer clearfix">
<div class="article-catetags">

<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/typhoon/categories/java性能优化/">java性能优化</a>
</div>


  <div class="article-tags">
  
  <span></span> <a href="/typhoon/tags/ListenableFuture/">ListenableFuture</a>
  </div>

</div>



	<div class="article-share" id="share">
	
	  <div data-url="http://scorpioaeolus.oschina.io/2018/09/21/ListenableFuture并发编程/" data-title="ListenableFuture并发编程 | Typhoon&#39;s code space" data-tsina="null" class="share clearfix">
	  </div>
	
	</div>


</footer>

   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/typhoon/2018/09/21/EventBus观察者模式/" title="EventBus观察者模式">
  <strong>上一篇：</strong><br/>
  <span>
  EventBus观察者模式</span>
</a>
</div>


<div class="next">
<a href="/typhoon/2018/09/16/spring实现事务管理/"  title="spring实现事务管理">
 <strong>下一篇：</strong><br/> 
 <span>spring实现事务管理
</span>
</a>
</div>

</nav>

	


</div>  
      <div class="openaside"><a class="navbutton" href="#" title="Show Sidebar"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">Contents</strong>
 
 <ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#背景需求"><span class="toc-number">1.</span> <span class="toc-text">背景需求</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#方案分析"><span class="toc-number">2.</span> <span class="toc-text">方案分析</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#技术实现"><span class="toc-number">3.</span> <span class="toc-text">技术实现</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#优秀的ListenableFuture"><span class="toc-number">4.</span> <span class="toc-text">优秀的ListenableFuture</span></a></li></ol>
 
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="Hide Sidebar"></a></div>
<aside class="clearfix">

  


  
<div class="categorieslist">
	<p class="asidetitle">Categories</p>
		<ul>
		
		  
			<li><a href="/typhoon/categories/dubbo/" title="dubbo">dubbo<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java性能优化/" title="java性能优化">java性能优化<sup>17</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java源码分析/" title="java源码分析">java源码分析<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/motan/" title="motan">motan<sup>2</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/spring/" title="spring">spring<sup>11</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springboot/" title="springboot">springboot<sup>28</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springmvc/" title="springmvc">springmvc<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/容器/" title="容器">容器<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/工具/" title="工具">工具<sup>7</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/性能优化/" title="性能优化">性能优化<sup>5</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/架构/" title="架构">架构<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/案例分析/" title="案例分析">案例分析<sup>13</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/缓存/" title="缓存">缓存<sup>4</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/面试题/" title="面试题">面试题<sup>1</sup></a></li>
		  
		
		</ul>
</div>


  
<div class="tagslist">
	<p class="asidetitle">Tags</p>
		<ul class="clearfix">
		
			
				<li><a href="/typhoon/tags/springboot/" title="springboot">springboot<sup>28</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/java性能优化/" title="java性能优化">java性能优化<sup>9</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/限流/" title="限流">限流<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring5/" title="Spring5">Spring5<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/案例分析/" title="案例分析">案例分析<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/性能优化/" title="性能优化">性能优化<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring/" title="Spring">Spring<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo/" title="dubbo">dubbo<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/分页/" title="分页">分页<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/并发/" title="并发">并发<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/异常拦截/" title="异常拦截">异常拦截<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo分布式事务/" title="dubbo分布式事务">dubbo分布式事务<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/自带图片/" title="自带图片">自带图片<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/svn导出mvn项目/" title="svn导出mvn项目">svn导出mvn项目<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo过滤器/" title="dubbo过滤器">dubbo过滤器<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/排序性能对比/" title="排序性能对比">排序性能对比<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/ListenableFuture/" title="ListenableFuture">ListenableFuture<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/PropertyChangeListener/" title="PropertyChangeListener">PropertyChangeListener<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/jdbcTemplate高可用/" title="jdbcTemplate高可用">jdbcTemplate高可用<sup>1</sup></a></li>
			
		
		</ul>
</div>


  <div class="linkslist">
  <p class="asidetitle">Links</p>
    <ul>
        
          <li>
            
            	<a href="https://coderq.com" target="_blank" title="一个面向程序员交流分享的新一代社区">码农圈</a>
            
          </li>
        
          <li>
            
            	<a href="http://wuchong.me" target="_blank" title="Jark&#39;s Blog">Jark&#39;s Blog</a>
            
          </li>
        
    </ul>
</div>

  


  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS</a>
</div>

  <div class="weiboshow">
  <p class="asidetitle">Weibo</p>
    <iframe width="100%" height="119" class="share_self"  frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=119&fansRow=2&ptype=1&speed=0&skin=9&isTitle=1&noborder=1&isWeibo=0&isFans=0&uid=null&verifier=b3593ceb&dpc=1"></iframe>
</div>


</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<div class="line">
		<span></span>
		<div class="author"></div>
	</div>
	
	
	<section class="info">
		<p> Hello ,I&#39;m a java coder. <br/>
			This is my blog,believe it or not.</p>
	</section>
	 
	<div class="social-font" class="clearfix">
		
		
		
		
		
		
		
		
		
		
		<a href="mailto:ScorpioAeolus@163.com" target="_blank" class="icon-email" title="Email Me"></a>
		
	</div>
			
		

		<p class="copyright">
		Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/wuchong/jacman" target="_blank" title="Jacman">Jacman</a> © 2019 
		
		<a href="/typhoon/about" target="_blank" title="typhoon">typhoon</a>
		
		
		</p>
</div>
</footer>
    <script src="/typhoon/js/jquery-2.0.3.min.js"></script>
<script src="/typhoon/js/jquery.imagesloaded.min.js"></script>
<script src="/typhoon/js/gallery.js"></script>
<script src="/typhoon/js/jquery.qrcode-0.12.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
  
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else{
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  c.click(function(){
    ta.css('display', 'block').addClass('fadeIn');
  });
  o.click(function(){
    ta.css('display', 'none');
  });
  $(window).scroll(function(){
    ta.css("top",Math.max(140,320-$(this).scrollTop()));
  });
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina'),
      description = $this.attr('description');
  var html = [
  '<div class="hoverqrcode clearfix"></div>',
  '<a class="overlay" id="qrcode"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="微信"></a>',
  '<a href="http://widget.renren.com/dialog/share?resourceUrl=' + encodedUrl + '&srcUrl=' + encodedUrl + '&title=' + title +'" class="article-share-renren" target="_blank" title="人人"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="微博"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);

  $('.hoverqrcode').hide();

  var myWidth = 0;
  function updatehoverqrcode(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
    var qrsize = myWidth > 1024 ? 200:100;
    var options = {render: 'image', size: qrsize, fill: '#2ca6cb', text: url, radius: 0.5, quiet: 1};
    var p = $('.article-share-qrcode').position();
    $('.hoverqrcode').empty().css('width', qrsize).css('height', qrsize)
                          .css('left', p.left-qrsize/2+20).css('top', p.top-qrsize-10)
                          .qrcode(options);
  };
  $(window).resize(function(){
    $('.hoverqrcode').hide();
  });
  $('.article-share-qrcode').click(function(){
    updatehoverqrcode();
    $('.hoverqrcode').toggle();
  });
  $('.article-share-qrcode').hover(function(){}, function(){
      $('.hoverqrcode').hide();
  });
});   
</script>









<link rel="stylesheet" href="/typhoon/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/typhoon/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.article-content').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });
  if($.fancybox){
    $('.fancybox').fancybox();
  }
}); 
</script>



<!-- Analytics Begin -->



<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?e6d1f421bbc9962127a50488f9ed37d1";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>



<!-- Analytics End -->

<!-- Totop Begin -->

	<div id="totop">
	<a title="Back to Top"><img src="/typhoon/img/scrollup.png"/></a>
	</div>
	<script src="/typhoon/js/totop.js"></script>

<!-- Totop End -->

<!-- MathJax Begin -->
<!-- mathjax config similar to math.stackexchange -->


<!-- MathJax End -->

<!-- Tiny_search Begin -->

<!-- Tiny_search End -->

  </body>
</html>
